package com.jackson.spring.aopdemo.aop;

import java.util.Arrays;
import java.util.List;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;


/**
 * 把这个类声明成一个切面：需要把该类放入到IOC容器中、在声明为一个切面
 * @author jackson
 *
 */
@Aspect
@Component
public class LogginAspect {

	//声明该方法是一个前置通知：在目标方法开始之前执行
//	@Before("execution(public int com.jackson.spring.aopdemo.aop.impl.ArithmeticCalculatorImpl.add(int, int))")
	@Before("execution(* com.jackson.spring.aopdemo.aop.impl.*.*(int, int))")
	public void beforemethod(JoinPoint joinPoint){
		String methodName = joinPoint.getSignature().getName();
		System.out.println("the mothod begin" +methodName +"  with "+Arrays.asList(joinPoint.getArgs()));
	}
	
	//在目标方法执行后执行的通知，无论是否发生异常
	//在后置通知中还不能访问目标方法执行的结果
	@After("execution(* com.jackson.spring.aopdemo.aop.impl.*.*(int, int))")
	public void aftermethod(JoinPoint joinPoint){
		String methodName = joinPoint.getSignature().getName();
		System.out.println("the mothod  end " +methodName);
	}
}
